package com.wicket.okrbff.biz.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.wicket.okrbff.biz.service.TemplateEngineService;
import com.wicket.okrbff.biz.service.dto.req.*;
import com.wicket.okrbff.biz.service.dto.res.*;
import com.wicket.okrbff.common.ro.OkrResult;
import com.wicket.okrbff.common.ro.OkrResult;
import com.wicket.okrbff.common.util.CommonFunctionHelper;
import com.wicket.okrbff.common.util.RedisUtil;
import javax.annotation.Resource;

import com.wicket.okrcomponent.integration.dto.QueryConfItemMatchAnswerDetailComReqDto;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import com.wicket.okrcomponent.integration.FwCompConfSchemeClient;
import com.wicket.okrcomponent.integration.dto.QueryConfItemMatchAnswerDetailComRespDto;
//import com.wicket.okrapp.integration.dto.QueryConfItemMatchAnswerDetailComReqDto;
import com.wicket.okrframework.integration.FwBaseUserClient;
import com.wicket.okrframework.integration.dto.QueryUserInfoDetailComRespDto;
import com.wicket.okrframework.integration.dto.QueryUserInfoDetailComReqDto;
import com.wicket.okrcomponent.integration.FwCompTemplateEngineClient;
import com.wicket.okrcomponent.integration.dto.GenerateSemanticInstanceStoryComRespDto;
import com.wicket.okrcomponent.integration.dto.GenerateSemanticInstanceStoryComReqDto;
import com.wicket.okrbff.common.exception.Assert;

/**
 * @author ：
 * @date ：
 *
 *
 * @version 1.0
 */
@Service
public class TemplateEngineServiceImpl implements TemplateEngineService {

  @Resource
  private RedisUtil redisUtil;
@Resource
  FwCompConfSchemeClient fwCompConfSchemeClient;

@Resource
  FwBaseUserClient fwBaseUserClient;

@Resource
  FwCompTemplateEngineClient fwCompTemplateEngineClient;
/**
   * B2生成回退预制消息内容[8497]
   * gen by moon at 2/17/2024, 10:59:02 PM
   */
    @Trace(operationName = "B2生成回退预制消息内容")
    @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Override
  public BffGenerateBackPrefabricateMsgContentRespDto generateBackPrefabricateMsgContent(BffGenerateBackPrefabricateMsgContentReqDto reqDto){
      
       
       GenerateSemanticInstanceStoryComRespDto generateSemanticInstanceStoryComRespDto_1 =null;
//步骤0: D2-3查配置项匹配答案详情(公共)（跨服务） - queryConfItemMatchAnswerDetailCom
     QueryConfItemMatchAnswerDetailComRespDto queryConfItemMatchAnswerDetailComRespDto = null;
    QueryConfItemMatchAnswerDetailComReqDto queryConfItemMatchAnswerDetailComReqDto=new QueryConfItemMatchAnswerDetailComReqDto();
  queryConfItemMatchAnswerDetailComReqDto.setConfItemCode("MESSAGE_SENDER_CONF");//CUSTOM_CONVENTION//sourceId:1547181_1
  queryConfItemMatchAnswerDetailComReqDto.setConfSchemeCode("COM_CONF_SCHEME");//CUSTOM_CONVENTION//sourceId:1547182_1
queryConfItemMatchAnswerDetailComReqDto.setIsPlatData("TRUE");//sourceId:1547183_1
if(reqDto!=null){
      queryConfItemMatchAnswerDetailComReqDto.setConfOptionCode(reqDto.getSendMsgScene());//SimpleFieldAssign//sourceId:1551807_1
    }
  
    /*D2查平台发送消息场景匹配消息内容语义引擎模板答案[2486]   */
    Assert.isNull(queryConfItemMatchAnswerDetailComReqDto.getConfOptionCode(),"B2生成回退预制消息内容-D2查平台发送消息场景匹配消息内容语义引擎模板答案-选项标识不能为空",false);
    Assert.isNull(queryConfItemMatchAnswerDetailComReqDto.getConfItemCode(),"B2生成回退预制消息内容-D2查平台发送消息场景匹配消息内容语义引擎模板答案-配置项标识不能为空",false);
Assert.isNull(queryConfItemMatchAnswerDetailComReqDto.getConfSchemeCode(),"B2生成回退预制消息内容-D2查平台发送消息场景匹配消息内容语义引擎模板答案-配置方案标识不能为空",false);
Assert.isNull(queryConfItemMatchAnswerDetailComReqDto.getIsPlatData(),"B2生成回退预制消息内容-D2查平台发送消息场景匹配消息内容语义引擎模板答案-是否标准答案不能为空",false);
      queryConfItemMatchAnswerDetailComRespDto = fwCompConfSchemeClient.queryConfItemMatchAnswerDetailCom(queryConfItemMatchAnswerDetailComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;
      
      
      
    
//步骤1: D1-2查询个人资料详情(公共) - queryUserInfoDetailCom
     QueryUserInfoDetailComRespDto queryUserInfoDetailComRespDto = null;
    QueryUserInfoDetailComReqDto queryUserInfoDetailComReqDto=new QueryUserInfoDetailComReqDto();
  queryUserInfoDetailComReqDto.setUserId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecUserId());//CURRENT_USERID//sourceId:1547200_1
  
    /*D1-2查当前用户真实姓名(用于生成消息内容入参)[408]   */
    Assert.isNull(queryUserInfoDetailComReqDto.getUserId(),"B2生成回退预制消息内容-D1-2查当前用户真实姓名(用于生成消息内容入参)-账号不能为空",false);
      queryUserInfoDetailComRespDto = fwBaseUserClient.queryUserInfoDetailCom(queryUserInfoDetailComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;
      
      
      
    
//步骤2: D2生成语义实例故事(公共) - generateSemanticInstanceStoryCom
     GenerateSemanticInstanceStoryComRespDto generateSemanticInstanceStoryComRespDto = null;
    if(queryConfItemMatchAnswerDetailComRespDto !=null){
          GenerateSemanticInstanceStoryComReqDto generateSemanticInstanceStoryComReqDto=new GenerateSemanticInstanceStoryComReqDto();
  generateSemanticInstanceStoryComReqDto.setFirstFieldName("idCardName");//CUSTOM_CONVENTION//sourceId:1547150_1
if(queryConfItemMatchAnswerDetailComRespDto!=null){
      generateSemanticInstanceStoryComReqDto.setTemplateSemanticEngineCode(queryConfItemMatchAnswerDetailComRespDto.getExtensionField2());//SimpleFieldAssign//sourceId:1547156_1
    }
if(queryUserInfoDetailComRespDto!=null){
      generateSemanticInstanceStoryComReqDto.setFirstFieldValue(queryUserInfoDetailComRespDto.getIdCardName());//SimpleFieldAssign//sourceId:1547151_1
    }
  
    /*D2生成语义实例故事(公共)[8234]   */
    Assert.isNull(generateSemanticInstanceStoryComReqDto.getTemplateSemanticEngineCode(),"B2生成回退预制消息内容-D2生成语义实例故事(公共)-模板引擎标识不能为空",false);
Assert.isNull(generateSemanticInstanceStoryComReqDto.getFirstFieldName(),"B2生成回退预制消息内容-D2生成语义实例故事(公共)-第一个字段字段名不能为空",false);
Assert.isNull(generateSemanticInstanceStoryComReqDto.getFirstFieldValue(),"B2生成回退预制消息内容-D2生成语义实例故事(公共)-第一个字段字段值不能为空",false);
      generateSemanticInstanceStoryComRespDto = fwCompTemplateEngineClient.generateSemanticInstanceStoryCom(generateSemanticInstanceStoryComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;
      
      
      generateSemanticInstanceStoryComRespDto_1 = generateSemanticInstanceStoryComRespDto;
           }
    
BffGenerateBackPrefabricateMsgContentRespDto retData = new BffGenerateBackPrefabricateMsgContentRespDto();
  if(generateSemanticInstanceStoryComRespDto_1!=null){
      retData.setMessageContent(generateSemanticInstanceStoryComRespDto_1.getObjectName());//SimpleFieldAssign//sourceId:1547202_1
    }
  

  
  
return retData;
  }
  //
}
